package com.example.goodpet.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.example.goodpet.R;
import com.example.goodpet.captcha.Captcha;

public class ShowVerificationActivity extends Activity {

    private Captcha captcha;



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verification);

        captcha = findViewById(R.id.captCha);
        captcha.setMaxFailedCount(5);

        initListener();
    }

    private void initListener() {
        captcha.setCaptchaListener(new Captcha.CaptchaListener() {
            @Override
            public String onAccess(long time) {
                //Toast.makeText(ShowVerificationActivity.this,"验证通过,耗时\"+time+\"毫秒",Toast.LENGTH_SHORT).show();
                setResult(RESULT_OK);
                finish();
                return "";
            }

            @Override
            public String onFailed(int failedCount) {
                Toast.makeText(ShowVerificationActivity.this,"验证失败",Toast.LENGTH_SHORT).show();
                captcha.reset(false);
                return "验证失败,已失败"+failedCount+"次";
            }

            @Override
            public String onMaxFailed() {
                Toast.makeText(ShowVerificationActivity.this,"验证超过次数",Toast.LENGTH_SHORT).show();
                setResult(RESULT_CANCELED);
                finish();
                return "验证失败,帐号已封锁";
            }
        });

    }
}
